package com.example.controller;

import com.example.EchartTypeEnum;
import com.example.annotation.rest.AnonymousGetMapping;
import com.example.pojo.ResultVo;
import com.example.service.CountChartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 描述
 *
 * @Author xulitao
 * @Date 2022/3/12
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/echart")
@CrossOrigin
@Api("统计模块")
public class CountChartController {

    @Autowired
    private CountChartService service;

    @AnonymousGetMapping("/getInteractiveCount")
    @ApiOperation("统计学生互动情况 1是饼状图  2 是柱状图")
    public ResultVo getPlayNum(@RequestParam Integer type) {
        ResultVo resultVo = new ResultVo();
        resultVo.setData(service.getPlayNum(type));
        return resultVo;
    }

    @AnonymousGetMapping("/workScore")
    public ResultVo getWorkNum(@RequestParam Integer type) {
        ResultVo resultVo = new ResultVo();
        resultVo.setData(service.getWorkScore(type));
        return resultVo;
    }

    @AnonymousGetMapping("/getScoreCount")
    @ApiOperation("考试成绩统计 type:1-柱状 3-折线")
    public ResultVo getScoreCount(@RequestParam String type) {
        return service.getScoreCount(type);
    }

    @AnonymousGetMapping("/getStuentSelect")
    public ResultVo getStuentSelect() {
        ResultVo resultVo = new ResultVo();
        List list = new ArrayList();
        for (EchartTypeEnum value : EchartTypeEnum.values()) {
            HashMap map = new HashMap();
            map.put("value", value.getType());
            map.put("label", value.getName());
            list.add(map);
        }
        resultVo.setData(list);
        return resultVo;
    }
}
